<html>
<head><meta charset="utf-8"><title>Writing debuggers · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20debuggers.html">Writing debuggers</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="226679005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20debuggers/near/226679005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark R. Tuttle <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20debuggers.html#226679005">(Feb 17 2021 at 16:02)</a>:</h4>
<p>What is the best approach to mapping values for MIR variables back to values for Rust variables?</p>
<p>We are writing a verification tool and have a tool for displaying error traces to the user, but the tool works on MIR and the trace is rendered as</p>
<ul>
<li>A sequence of assignments to MIR variables, and we'd like to turn it into a sequence of assignments to Rust variables.</li>
<li>Annotated html stepping through lines of the Rust program, and we would like to render the trace in visual studio code, probably as a new kind of debugger.</li>
</ul>
<p>We have read the <a href="https://rustc-dev-guide.rust-lang.org/">rustc developer's guide</a> and know about the HIR but had not made use of it yet.</p>



<a name="226679850"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20debuggers/near/226679850" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20debuggers.html#226679850">(Feb 17 2021 at 16:06)</a>:</h4>
<p>Take a look at the <code>var_debug_info</code> field of <code>mir::Body</code>. For stepping through lines, every statement and terminator has <code>SourceInfo</code> associated with it. This contains the span of the code.</p>



<a name="226679904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20debuggers/near/226679904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20debuggers.html#226679904">(Feb 17 2021 at 16:06)</a>:</h4>
<p>There is no mapping from MIR back to HIR.</p>



<a name="226760704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20debuggers/near/226760704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mark R. Tuttle <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20debuggers.html#226760704">(Feb 18 2021 at 03:32)</a>:</h4>
<p>Thanks for this help.  We knew about <code>SourceInfo</code> but not <code>var_debug_info</code>.</p>



<a name="237889929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Writing%20debuggers/near/237889929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hkalbasi <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Writing.20debuggers.html#237889929">(May 07 2021 at 21:04)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Writing.20debuggers/near/226679904">said</a>:</p>
<blockquote>
<p>There is no mapping from MIR back to HIR.</p>
</blockquote>
<p>I want to find out which function contains this <code>LocalDecl</code> (Which if I understand correctly, there is just one function at a time that has MIR representation) So If I want HIR of that function, what should I do? I need HIR for finding is that function inside of impl of trait or not.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>